////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011-2012 www.iflytek.com. All Rights Reserved.
//  This software for customer relationship management system, developed by Noo team.
//  Software code and design for the team, copy rights reserved.
////////////////////////////////////////////////////////////////////////////////

package com.iflytek.ci.main.controller;

import java.util.List;

import com.iflytek.ci.cpms.domain.Project;
import com.iflytek.ci.cpms.service.ProjectService;
import com.iflytek.ci.cums.service.impl.ShiroDbRealm;
import com.iflytek.ci.qams.domain.Issue;
import com.iflytek.ci.qams.service.IssueService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 首页内容服务.
 * </p>
 *
 * @author poplar.yfyang
 * @version 1.0 2012-10-25 10:22 PM
 * @since JDK 1.5
 */
@Controller
public class DashboardController extends BaseController {
	/** serila version */
	private static final long serialVersionUID = -4433441847033575826L;
	/** 问题服务 */
	@Autowired
	private IssueService issueService;
	
	/** 项目服务 获取用户所在项目列表 */
	@Autowired
	private ProjectService projectService;

	/**
	 * 获取当前登录人 登录帐号
	 *
	 * @return 登录人帐号
	 */
	private static String login() {
		ShiroDbRealm.ShiroUser shiroUser = (ShiroDbRealm.ShiroUser) SecurityUtils.getSubject().getPrincipal();
		return shiroUser.getLogin();
	}

	/**
	 * 首页信息定向
	 *
	 * @return view 页面地址
	 */
	@RequestMapping("/dashboard")
	public String init() {
		return "dashboard";
	}

	/**
	 * 获取当前登录人的待办事项的总数
	 *
	 * @return 待办事项总数
	 */
	@RequestMapping("/todo_count")
	@ResponseBody
	public Integer login_count_todo() {
		return issueService.get_count_todo(login());
	}

	/**
	 * 获取当前登录人的已报告的问题
	 *
	 * @return 报告数量
	 */
	@RequestMapping("/report_count")
	@ResponseBody
	public Integer report_count() {
		return issueService.get_number_reporte(login());
	}

	/**
	 * 获取指派给当前登录人的前十条任务，按优先级和创建时间
	 *
	 * @return ajax信息，待办事项的前十
	 */
	@RequestMapping("/assigin_me")
	@ResponseBody
	public List<Issue> login_todo_issue() {
		return issueService.issue_assignee_order(login());
	}

	/**
	 * 获取当前登录人发起的前十条信息。
	 *
	 * @return ajax信息，我发起的反馈问题的前十
	 */
	@RequestMapping("report_me")
	@ResponseBody
	public List<Issue> report_me_issues() {

		return issueService.issue_reporter_order(login());
	}
	
	@RequestMapping("/my_projects")
	@ResponseBody
	public List<Project> get_my_projects(){
		return projectService.get_project();
	}

}
